package com.group9.handinhand.dao;

import org.springframework.stereotype.Repository;

import com.group9.handinhand.dao.model.AbstractBaseModel;
import com.group9.handinhand.dao.model.Goods;
import com.group9.handinhand.dao.model.Services;
import com.group9.handinhand.dao.model.Skill;
/**
 * class for Activities for Database Access Object
 *
 */
@Repository
public class ActivityDao extends BaseDaoImpl {
	/**
	 * saves goods as good object
	 * @param goods
	 * @return goods
	 */
	public Goods saveGoods(Goods goods) {
		save(goods);
		return goods;
	}
	/**
	 * saves services as service object
	 * @param service
	 * @return
	 */
	public Services saveService(Services service) {
		save(service);
		return service;
	}
	/**
	 * saves skills as skill object
	 * @param skill
	 * @return
	 */
	public Skill saveSkill(Skill skill) {
		save(skill);
		return skill;
	}
	/**
	 * updates goods
	 * @param goods
	 * @return
	 */
	public Goods updateGoods(Goods goods) {
		update(goods);
		return goods;
	}
	/**
	 * updates services
	 * @param services
	 */
	public void updateServices(Services services) {
		update(services);
	}
	/**
	 * returns the service according to offer id
	 * @param offerId
	 * @return
	 */
	public Services findServiceByOfferId(Long offerId) {
		String queryString = "Select os from Offer o inner join o.service os where o.id =:offerId";
		return executeQueryStringForObject(queryString,new String[]{"offerId"}, new Object[]{offerId});
	}
	/**
	 * merges service
	 * @param service
	 */
	public void mergeServices(Services service) {
		merge(service);
	}
	/**
	 * merges skill
	 * @param skill
	 */
	public void mergeSkill(Skill skill) {
		merge(skill);
	}
	/**
	 * finds skill according to service id
	 * @param serviceId
	 * @return
	 */
	public Skill findSkillByServiceId(Long serviceId) {
		String queryString = "Select sr from Services s inner join s.requiredSkill sr where s.id =:serviceId";
		return executeQueryStringForObject(queryString,new String[]{"serviceId"}, new Object[]{serviceId});
	}
	/**
	 * finds good according to offer id
	 * @param offerId
	 * @return
	 */
	public Goods findGoodByOfferId(Long offerId) {
		String queryString = "Select og from Offer o inner join o.goods og where o.id =:offerId";
		return executeQueryStringForObject(queryString,new String[]{"offerId"}, new Object[]{offerId});
	}
	/**
	 * merges good
	 * @param good
	 */
	public void mergeGoods(Goods good) {
		merge(good);
	}
	/**
	 * finds service according to request id
	 * @param requestId
	 * @return
	 */
	public Services findServiceByRequestId(Long requestId) {
		String queryString = "Select rs from Request r inner join r.service rs where r.id =:requestId";
		return executeQueryStringForObject(queryString,new String[]{"requestId"}, new Object[]{requestId});
	}
	/**
	 * finds good by request id
	 * @param requestId
	 * @return
	 */
	public Goods findGoodByRequestId(Long requestId) {
		String queryString = "Select rg from Offer r inner join r.goods rg where r.id =:requestId";
		return executeQueryStringForObject(queryString,new String[]{"requestId"}, new Object[]{requestId});
	}
	
}
